import request from '@/utils/request'

// ========== 广告管理 ==========

export function fetchAdvertisementList(params) {
  return request({
    url: '/content/advertisements',
    method: 'get',
    params: params
  })
}

export function createAdvertisement(data) {
  return request({
    url: '/content/advertisements',
    method: 'post',
    data: data
  })
}

export function updateAdvertisement(id, data) {
  return request({
    url: `/content/advertisements/${id}`,
    method: 'put',
    data: data
  })
}

export function deleteAdvertisement(id) {
  return request({
    url: `/content/advertisements/${id}`,
    method: 'delete'
  })
}

// ========== 公告管理 ==========

export function fetchAnnouncementList(params) {
  return request({
    url: '/content/announcements',
    method: 'get',
    params: params
  })
}

export function createAnnouncement(data) {
  return request({
    url: '/content/announcements',
    method: 'post',
    data: data
  })
}

export function getAnnouncement(id) {
  return request({
    url: `/content/announcements/${id}`,
    method: 'get'
  })
}

export function updateAnnouncement(id, data) {
  return request({
    url: `/content/announcements/${id}`,
    method: 'put',
    data: data
  })
}

// 更新公告发布状态的专用接口
export function updateAnnouncementPublishStatus(id, isPublished) {
  return request({
    url: `/content/announcements/${id}/publish-status`,
    method: 'patch',
    data: {
      is_published: isPublished
    }
  })
}

// 更新公告置顶状态的专用接口
export function updateAnnouncementPinStatus(id, isPinned) {
  return request({
    url: `/content/announcements/${id}/pin-status`,
    method: 'patch',
    data: {
      is_pinned: isPinned
    }
  })
}

export function deleteAnnouncement(id) {
  return request({
    url: `/content/announcements/${id}`,
    method: 'delete'
  })
}

// ========== 图片上传 ==========

export function uploadImage(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/content/upload-image',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
